home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Games World / Hot Demos! / DroidWorks demo / dwCD.gob / mission_cog_b0_gear.cog < prev    next >
Text File  |  1998-09-17  |  19KB  |  558 lines

  1. # Droids Cog Script
  2. #
  3. # b0_Gear.cog
  4. #
  5. # Gear Cog controlling movement of the bridge and gears assmebly. 
  6. #
  7. # Desc:
  8. #     bin 25    Small Gears
  9. #     bin 26    Medium Gear
  10. #     bin 27     Large Gear
  11. #    This cog is responsible for keeping track of what gears are in the Gear assembly 
  12. #    and where. It's also in charge of mocing the bridge either up or down depending on 
  13. #    how the gears are in place. There are seperate cogs for the gear pieces themselves
  14. #    when found on the ground. After they've been placed in the gear assembly, they're 
  15. #    part of this script.
  16. #           
  17. #
  18. # 10/23/97 [DGS]    Created 
  19. # 01/19/97 [DGS]    Updated for new controls.    
  20. # 01/21/97 [DGS]    Rewrote majority of it; added new Used and Taken sections       
  21. # ========================================================================================
  22.  
  23. symbols
  24. message        used
  25. message        startup        
  26. message        arrived
  27. message        user0
  28. message        taken
  29. message        timer        
  30.  
  31. ## ================Parts    
  32. thing        screw0        linkid=11 
  33. thing        screw1         linkid=11
  34. thing        screw2        linkid=11
  35. thing        screw3        linkid=11
  36. thing        gear_top    linkid=11
  37. thing        gear_bot    linkid=11
  38. thing        platform    linkid=3 
  39. thing        spind        linkid=11
  40. surface        Button0        linkid=2
  41.  
  42. ## ==================Ghost objects
  43. thing        l_spindle_g        linkid=30  
  44. thing        r_spindle1_g    linkid=31  
  45. thing        r_spindle2_g    linkid=32  
  46.  
  47. ## ===================Ghost creation integers
  48. int        l_spindle_i=0      linkid=11        local
  49. int        r_spindle1_i=0                    local
  50. int        r_spindle2_i=0                    local
  51.  
  52. ## ====================Spin Directon integers
  53. flex        l_spindle_d=0.0        local
  54. flex        r_spindle1_d=0.0    local
  55. flex        r_spindle2_d=0.0    local
  56. flex        t_gear_d=0.0        local
  57.  
  58. ## =====================templates
  59. template    gear_large_t    
  60. template    gear_small_t
  61. template    gear_med_t
  62.  
  63. ## ======================Sectors
  64. sector        L_Sector    
  65. sector         R_sector
  66.  
  67. ## ======================Sounds
  68. sound        gearon_snd
  69. sound        gearongfsdfsf_snd
  70. sound        gearoff_snd
  71. sound        mstart_snd
  72. sound        mstop_snd
  73. sound        mfree_snd
  74. sound        mstress_snd
  75. sound        gearbog_snd
  76.  
  77. ## ======================Cogs
  78. cog        button_cog
  79.  
  80. thing    ghost_cam
  81. int        l_spindle_m=0        local
  82. int        r_spindle1_m=0        local
  83. int        r_spindle1_m=0        local
  84.  
  85.  
  86.  
  87. ## ======================Internal variables 
  88. float    speed=2.0            local
  89. int        on_button=0            local
  90. int        rotate                local
  91. int        l_spindle=0            local
  92. int        r_spindle1=0        local
  93. int        r_spindle2=0        local
  94. int        timermode=0            local
  95. int        part_id=0            local
  96. int        g_sound=0            local
  97. end
  98. # ========================================================================================
  99.  
  100. code
  101.                
  102. startup:
  103.     // 
  104.     //print("rotate it");
  105.     //rotate = 1;
  106.     //l_spindle_d     =     1;
  107.     //r_spindle1_d    =     -0.5;
  108.     //r_spindle2_d    =      0.5;
  109.         //call rotate_gears;
  110.     
  111.     
  112.     AttachThingToThing(screw0, gear_top);
  113.     AttachThingToThing(screw1, gear_top);
  114.     AttachThingToThing(screw2, gear_top);
  115.     AttachThingToThing(ghost_cam, platform);
  116.     //AttachThingToThing(screw3, screw0);
  117.     
  118.     MoveToFrame(platform, 1, 50);
  119.     //RotatePivot(screw0, 1, 1);
  120.  
  121.     sleep(5);
  122.     print("Gear mode:");
  123.     printint(screw0);
  124.     printint(screw1);
  125.     printint(screw2);
  126.  
  127.     return;
  128.  
  129. # ........................................................................................
  130. user0:
  131.         // User0 gets called when the player hits the motor switch. See gear_activate.cog 
  132.         print("user0");
  133.         if (rotate == 0) call start_motor;
  134.     return;
  135. used:
  136.     //    Section is executed when the user uses an inventory object. Cool. 
  137.     print("USED:");
  138.     printint(dwGetActivateBin());
  139.     printint(getsenderid());
  140.     if (rotate == 0)
  141.         {
  142.         if ( getinv(getlocalplayerthing(),dwGetActivateBin()) > 0) //if the bin has more than 0 in it; 
  143.             {
  144.             if ((GetSenderId() == 11) || (getsenderref() == r_spindle1_i) || (getsenderref() == r_spindle2_i)) // It's used on the gear_bot    
  145.                 {
  146.                 //    The Gear Assembly was activated
  147.                 if (getthingsector(getlocalplayerthing()) == l_sector) 
  148.                     {
  149.                     //=================== Player is on the Large gear side of the gear assembly
  150.                     print("Activated L sector");
  151.                     call handle_l;
  152.                     }
  153.                     
  154.                 if (getthingsector(getlocalplayerthing()) == r_sector) 
  155.                     {
  156.                     //=================== Player is on the Small gear side of the gear assembly
  157.                     print("Activated R sector");
  158.                     call handle_r;
  159.                     }
  160.                 }
  161.             }
  162.         }
  163.     return;
  164.  
  165.  
  166. taken:
  167.     print("taken");
  168.     printint(r_spindle1_i);
  169.         printint(r_spindle2_i);
  170.     printint(getsenderref());
  171.     printint ((GetSenderId() == 11) || (getsenderref() == r_spindle1_i) || (getsenderref() == r_spindle1_i));
  172.  
  173.     // Taken gets called when the user attempts to take a gear from left or right of the gear assembly.    
  174.         if (rotate == 0)
  175.         {
  176.         if ((GetSenderId() == 11)) // if it's the gear_bot that got activated    
  177.             {
  178.             print("Inside");
  179.             //    The Gear Assembly was activated
  180.             if (getthingsector(getlocalplayerthing()) == l_sector) 
  181.                 {
  182.                 //=================== Player is taking stuff from the left side of the gear assembly
  183.                 if (l_spindle != 0)
  184.                     {
  185.                     // inc the bin to add it back to the inv, destroy the environment one ans set l_spindle to 0.
  186.                     ChangeInv(getlocalplayerthing(), l_spindle, 1);
  187.                     destroything(l_spindle_i);
  188.                     l_spindle = 0;        
  189.                     //dwSetPlayerMass(dwGetPlayerMass() + l_spindle_m);
  190.                     l_spindle_m = 0;
  191.                     
  192.                     call update_bins;
  193.                     PlaySoundThing(gearoff_snd, l_spindle_g, 1, -1, -1, 0);  
  194.                     }
  195.                 else
  196.                     {
  197.                     // TELL THE PLAYER THERE'S NOTHING TO TAKE
  198.                     dwPlayCammySpeech(17305, "t9ca006.wav", 10, 0);
  199.                     timermode = 2;
  200.                     settimer(10);
  201.                     }
  202.                 }
  203.                 
  204.             if (getthingsector(getlocalplayerthing()) == r_sector) 
  205.                 {
  206.                 //=================== Player is on the Small gear side of the gear assembly
  207.                 if (r_spindle1 != 0)    //if the top spindle (1) has something on it.
  208.                     {
  209.                     // inc the bin to add it back to the inv, destroy the environment one ans set r_spindle1 to 0.
  210.                     ChangeInv(getlocalplayerthing(), r_spindle1, 1);
  211.                     //releasething(r_spindle1_i);
  212.                     destroything(r_spindle1_i);
  213.                     r_spindle1 = 0;        
  214.                     //dwSetPlayerMass(dwGetPlayerMass() + r_spindle1_m);
  215.                     r_spindle1_m - 0;
  216.                     
  217.                     call update_bins;
  218.                     PlaySoundThing(gearoff_snd, r_spindle1_g, 1, -1, -1, 0);  
  219.                     }
  220.                 else if (r_spindle2 != 0)    //if the bottom spindle (2) has something on it
  221.                     {
  222.                     // inc the bin to add it back to the inv, destroy the environment one ans set r_spindle2 to 0.
  223.                     ChangeInv(getlocalplayerthing(), r_spindle2, 1);
  224.                     //releasething(r_spindle2_i);
  225.                     destroything(r_spindle2_i);
  226.                     r_spindle2 = 0;        
  227.                     //dwSetPlayerMass(dwGetPlayerMass() + r_spindle2_m);
  228.                     r_spindle2_m - 0;
  229.                     PlaySoundThing(gearoff_snd, r_spindle1_g, 1, -1, -1, 0);  
  230.                     call update_bins;
  231.                     }
  232.                 else     //else there's nothing on this side. Both spindles are empty.
  233.                     {
  234.                     dwPlayCammySpeech(17305, "t9ca006.wav", 10, 0);  //There's nothing to take
  235.                     timermode = 2;
  236.                     settimer(10);
  237.                     }
  238.                 }
  239.             }
  240.         }
  241.     return;
  242. grind_gears:
  243.         // Controls causing the grind sound .
  244.         garbage = PlaySoundThing(gearbog_snd, gear_bot, 1, -1, -1, 0);
  245.         dwPlayCammySpeech(17313, "t9ca014.wav", 10, 0);
  246.         timermode = 3;
  247.         settimer(1);
  248.     return;
  249.  
  250. start_motor:
  251.     if ( (l_spindle == 27) && (r_spindle1 == 25) && (r_spindle2 == 25) )        // if all the grears are in place
  252.         {
  253.         r_spindle2_d    = 0;
  254.         r_spindle1_d     = 0;
  255.         l_spindle_d     = 0;
  256.         // 
  257.         call grind_gears;
  258.         }
  259.     else    // Else set up the way it's all gonna spin
  260.         { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Set motion/direction
  261.         t_gear_d = 0; //Assume that if the top gear is going to move, the below lines will set it that way.
  262.         // These if/else statements set up the speeds and directions for the gears on the 3 spindles. 
  263.         if (l_spindle == 27)//if it's the large gear in the left spindle  
  264.             {
  265.             l_spindle_d = -1; //set the direction to -0.5
  266.             t_gear_d = -0.5; //set the top gears direction. 
  267.             }
  268.         else l_spindle_d = 0;// else set the gears speed to 0, since md. and sm. gears don't touch the upper and lower gears when they're on the left.
  269.         
  270.         if (r_spindle2 == 25) 
  271.             {
  272.             r_spindle2_d = 0.5;// if the sm. gear is on the lower spindle then set its speed and dirction 
  273.             }
  274.         else r_spindle2_d = 0;// else set the gears speed to 0, since the sm. gear is the only one that can go on the lower spindle
  275.         
  276.         if ((r_spindle1 == 25) && (r_spindle2 == 25)) //if the upper gear is there and the lower gear is there 
  277.             {
  278.             r_spindle1_d = -0.5;// 
  279.             t_gear_d = 0.5; //set the top gears direction to move the platform up. 
  280.             }
  281.         else if ((r_spindle1 == 25) && (l_spindle == 27)) r_spindle1_d = 0.5;// if the lower gear and the lg. gear is there then set the speed.
  282.         else r_spindle1_d = 0;//else it's not going to spin when the switch is pulled.
  283.            
  284.  
  285.         printint(r_spindle2);
  286.         printflex(r_spindle2_d);
  287.         
  288.         if (t_gear_d > 0) //if the top gear is connected to the lower gear and spinning up 
  289.             {
  290.             if (GetCurFrame(platform) > 0) //if the platform's not already at the top
  291.                 {
  292.                 MoveToFrame(platform, GetCurFrame(platform)-1, speed);    //move the platform up
  293.                 dwPlayCammySpeech(17302, "t9ca004.wav", 10, 0);
  294.                 garbage = PlaySoundThing(mstart_snd, gear_bot, 1, -1, -1, 0);
  295.                 g_sound = PlaySoundThing(mstress_snd, gear_bot, 1, -1, -1, 1);
  296.                 
  297.                 call rotate_gears;
  298.                  timermode = 4;
  299.                 settimer(2);
  300.                 
  301.    
  302.                 }
  303.             else // else make the grinding sound
  304.                 {
  305.                 call grind_gears;
  306.                 }
  307.             }
  308.         else if (t_gear_d < 0) //else if the top gear is connected to the lower gear and spinning down 
  309.             {
  310.             if (GetCurFrame(platform) < 2) //if the platform's not already at the bottom
  311.                 {
  312.                 MoveToFrame(platform, GetCurFrame(platform)+1, speed);    //move the platform down
  313.                 dwPlayCammySpeech(17302, "t9ca004.wav", 10, 0);
  314.                 garbage = PlaySoundThing(mstart_snd, gear_bot, 1, -1, -1, 0);
  315.                 g_sound = PlaySoundThing(mstress_snd, gear_bot, 1, -1, -1, 1);
  316.                 
  317.                 call rotate_gears;
  318.                 timermode = 4;
  319.                 settimer(2);
  320.                 }
  321.             else // else make the grinding sound
  322.                 {
  323.                 call grind_gears;
  324.                 }
  325.             }
  326.         else    // else top Gear's not connected; spin the bottom  
  327.             {
  328.             //SET THE TIME
  329.             timermode = 1;// Timermode tells the timer what to do when it's called. 
  330.             settimer(10);
  331.             dwPlayCammySpeech(17315, "t9ca016.wav", 10, 0);
  332.             garbage = PlaySoundThing(mstart_snd, gear_bot, 1, -1, -1, 0);
  333.             g_sound = PlaySoundThing(mfree_snd, gear_bot, 1, -1, -1, 1);
  334.  
  335.             call rotate_gears;
  336.             }
  337.         }  
  338.     return;
  339.  
  340. rotate_gears:
  341.     //This routine starts the gears a spinnin'. After they're goin', continue_gears is used to keep the thing spinning.
  342.     rotate = 1;
  343.     //RotatePivot(screw0, 1, 1);
  344.     RotatePivot(gear_bot,         1,     0.5);
  345.     print("Rotates!");
  346.     printint(l_spindle_d);
  347.     if (!(l_spindle_d == 0.0))     RotatePivot(l_spindle_i,     1,     l_spindle_d);
  348.     if (!(r_spindle1_d == 0.0))    RotatePivot(r_spindle1_i,     1,     r_spindle1_d);
  349.     if (!(r_spindle2_d == 0.0))     RotatePivot(r_spindle2_i,       1,      r_spindle2_d);                                                                       
  350.         if (!(t_gear_d == 0.0))        RotatePivot(gear_top,         1,     t_gear_d);
  351.     return;
  352.  
  353.     
  354. continue_gears:
  355.     printint(getsenderid());
  356.         if (!(l_spindle_d == 0.0))     RotatePivot(l_spindle_i,     1,     l_spindle_d);
  357.     if (!(r_spindle1_d == 0.0))    RotatePivot(r_spindle1_i,     1,     r_spindle1_d);
  358.     if (!(r_spindle2_d == 0.0))     RotatePivot(r_spindle2_i,       1,      r_spindle2_d);                                                                       
  359.         if (!(t_gear_d == 0.0))        RotatePivot(gear_top,         1,     t_gear_d);
  360.     if (getsenderid() == 11)    RotatePivot(gear_bot,         1,     0.5);
  361.     return;
  362.  
  363. stop_gears:
  364.     //this routine stops all motion of the gears when it's called.       Hopefully. Otherwise, well. Otherwise. 
  365.     stopthing(r_spindle1_i);
  366.     stopthing(l_spindle_i);  
  367.     stopthing(r_spindle2_i);  
  368.     stopthing(gear_top);  
  369.     stopthing(gear_bot);
  370.     rotate = 0;
  371.     sendmessage(button_cog, user0);    
  372.     if (g_sound > 0) 
  373.         {
  374.         stopsound(g_sound,0.1);
  375.         garbage = PlaySoundThing(mstop_snd, gear_bot, 1, -1, -1, 0);  
  376.         }
  377.     timermode = 5;
  378.     settimer(1);
  379.     return;
  380.  
  381. handle_l:
  382.     // handle_l is used to put gears on the left side of the assembly. handle_r is for the right. Taken handles removing gears.
  383.     print("handle_l:");
  384.     if (l_spindle == 0)        //if the spindle is empty
  385.         {
  386.         //============ Add whatever you gots to the spindle
  387.         if ((dwGetActivateBin() > 24) && (dwGetActivateBin() < 94))    // if it's one of the gears that's being used
  388.             {
  389.             // 3 things happen here. First the variable l_spindle is set to the gear that's going to go on the spindle. 
  390.             // The bin number from the gear is used to represent what gear is on the spindle. if l_spindle is set to 0, then 
  391.             // there should be no gear on the spindle. If it's a non-zero number, it represents the present gear's bin number.   
  392.             l_spindle = dwGetActivateBin();
  393.             
  394.             // Next l_spindle is queried to figure out what gear is going to be created. Then it's created    
  395.             if (l_spindle == 25)
  396.                 {
  397.                 print("gear small");
  398.                 l_spindle_i = creatething(gear_small_t, l_spindle_g);
  399.                 l_spindle_m = 160;
  400.                 //dwSetPlayerMass(dwGetPlayerMass() - l_spindle_m);
  401.                 }
  402.             else if (l_spindle == 26)
  403.                 {
  404.                 l_spindle_i = creatething(gear_med_t, l_spindle_g);
  405.                 l_spindle_m = 200;
  406.                 //dwSetPlayerMass(dwGetPlayerMass() - l_spindle_m);
  407.                 print("gear med");
  408.                 }
  409.             else if (l_spindle == 27)
  410.                 {
  411.                 l_spindle_i = creatething(gear_large_t, l_spindle_g);
  412.                 l_spindle_m = 260;
  413.                 //dwSetPlayerMass(dwGetPlayerMass() - l_spindle_m);
  414.                 print("gear large");
  415.                 }
  416.                         // finally we decrement the bin that was activated. 
  417.             PlaySoundThing(gearon_snd, l_spindle_g, 1, -1, -1, 0);  
  418.             ChangeInv(getlocalplayerthing(), l_spindle, -1);
  419.             call update_bins;
  420.                         }
  421.                 }
  422.     else
  423.         {
  424.                 // TELL THE PLAYER THERE'S SOMETHING ON THE SPINDLE ALREADY
  425.         dwPlayCammySpeech(17304, "t9ca005.wav", 10, 0);
  426.         timermode = 2;
  427.         settimer(10); 
  428.         }
  429.         
  430.     return;
  431.  
  432. handle_r:
  433.     // handle_r controls putting gears on the right side of the assemebly. handle_l is the left side. Taken controls removing gears for both l and r. 
  434.     print("handle_r:");
  435.         if (r_spindle2 > 0)        //if the bottom spindle has something on it 
  436.         {
  437.         // check the top spindle 
  438.         if (r_spindle1 > 0)        //if the top spindle has something on it
  439.             {
  440.             // There's gears already here 
  441.             dwPlayCammySpeech(17304, "t9ca005.wav", 10, 0);
  442.             
  443.             timermode = 2;
  444.             settimer(10); 
  445.             }
  446.         else                //else the upper spindle is empty
  447.             {
  448.             //============ This section controls the upper spindle only (r_spindle1). 
  449.             
  450.             if (dwGetActivateBin() == 25)    // if it's the small gear
  451.                 {
  452.                 // check the comments from handle_l for info on the creation process of a gear. Then check with Doug
  453.                 r_spindle1 = dwGetActivateBin();
  454.                 r_spindle1_i = creatething(gear_small_t, r_spindle1_g);
  455.                 //capturething(r_spindle1_i);
  456.                 r_spindle1_m = 160;
  457.                 //dwSetPlayerMass(dwGetPlayerMass() - r_spindle1_m);
  458.                 
  459.                 ChangeInv(getlocalplayerthing(), r_spindle1, -1);
  460.                 PlaySoundThing(gearon_snd, r_spindle1_g, 1, -1, -1, 0);  
  461.                 
  462.                 call update_bins;
  463.                 }
  464.             else    //Else it's not the small gear
  465.                 {
  466.                 if ((dwGetActivateBin() > 25) && (dwGetActivatebin() < 28)) // If it's the med or large gear
  467.                     {
  468.                     dwPlayCammySpeech(17311, "t9ca012.wav", 10, 0);
  469.                     timermode = 2;
  470.                     settimer(10); 
  471.                     }
  472.                 }
  473.             
  474.             }
  475.         }
  476.     else        //else the bottom spindle is empty
  477.         {
  478.         if (dwGetActivateBin() == 25)    // if it's the small gear
  479.             {
  480.             // check the comments from handle_l for info on the creation process of a gear. Then check with Doug
  481.             r_spindle2 = dwGetActivateBin();
  482.             r_spindle2_i = creatething(gear_small_t, r_spindle2_g);
  483.             //capturething(r_spindle2_i);
  484.             r_spindle2_m = 160;
  485.             //dwSetPlayerMass(dwGetPlayerMass() - r_spindle2_m);
  486.             ChangeInv(getlocalplayerthing(), r_spindle2, -1);
  487.             PlaySoundThing(gearon_snd, r_spindle2_g, 1, -1, -1, 0);  
  488.             call update_bins;
  489.             }
  490.         else    //Else it's not the small gear
  491.             {
  492.             if ((dwGetActivateBin() > 25) && (dwGetActivatebin() < 28)) // If it's the med or large gear
  493.                 {
  494.                 dwPlayCammySpeech(17311, "t9ca012.wav", 10, 0);
  495.                 timermode = 2;
  496.                 settimer(10); 
  497.                 }
  498.             }
  499.             
  500.         }
  501.     return;
  502. # ............................................... .........................................
  503. arrived:
  504.     if ((GetSenderId() != 3) && (rotate == 1))
  505.         {
  506.         call continue_gears;
  507.         }
  508.     if (GetSenderId() == 3)
  509.         {
  510.         call stop_gears;
  511.         rotate = 0;
  512.         }
  513.         return;
  514.  
  515. timer:
  516.         if (timermode == 1) //Will turn off the gears.
  517.         {
  518.         call stop_gears;
  519.         rotate = 0;
  520.         sendmessage(button_cog, user0);    
  521.         }
  522.     else if (timermode == 2) //will clear Cammy's text
  523.         {
  524.         }
  525.     else if (timermode == 3) //will clear Cammy's text and set the switch back to 0;
  526.         {
  527.         timermode = 2;
  528.         settimer(9);
  529.         sendmessage(button_cog, user0);    
  530.         }    
  531.     else if (timermode == 4) //ext. camera             
  532.         {
  533.         dwFreezePlayer();
  534.         SetCameraFocus(0, ghost_cam);
  535.         SetCurrentCamera(0);
  536.         }
  537.     else if (timermode == 5) //Reset camera to player.            
  538.         {
  539.         SetCurrentCamera(7);
  540.         dwunfreezeplayer();
  541.         }
  542.     return;
  543.     
  544. update_bins:
  545.     // this is a utility routine used to turn on and off availability of items. Just until Jon adds it into DW for reals.
  546.         if ( getinv(getlocalplayerthing(),25) > 0) SetInvAvailable(getlocalplayerthing(), 25, 1); //if the sm. bin has more than 0 turn on the inv icon; 
  547.     else SetInvAvailable(getlocalplayerthing(), 25, 0);    // else turn it off;
  548.     
  549.         if ( getinv(getlocalplayerthing(),26) > 0) SetInvAvailable(getlocalplayerthing(), 26, 1); //if the md. bin has more than 0 turn on the inv icon; 
  550.     else SetInvAvailable(getlocalplayerthing(), 26, 0);    // else turn it off;
  551.        
  552.         if ( getinv(getlocalplayerthing(),27) > 0) SetInvAvailable(getlocalplayerthing(), 27, 1); //if the lg. bin has more than 0 turn on the inv icon; 
  553.     else SetInvAvailable(getlocalplayerthing(), 27, 0);    // else turn it off;
  554.     return;
  555. end
  556.  
  557.